<?php
defined('BASEPATH') OR exit('No direct script access allowed');
?>
<!--返回错误信息-->
<?php echo validation_errors(); ?>
<!DOCTYPE html>
<html lang="en">

<head>
    <?php
    $title = [
        'title' => '统计分析管理/采购统计汇总',
    ];
    $this->load->view('/admin/common/header', $title);
    ?>
</head>

<body data-type="widgets" style="overflow: auto;">
<script src="/assets/js/theme.js"></script>
<div class="am-g tpl-g">

    <!--    头部   侧边菜单-->
    <?php $this->load->view('/admin/common/bodyLeft'); ?>
    <script type="text/javascript">
        $(".js-sidebar-nav>li:nth-child(11)>ul").show(80);
        $(".js-sidebar-nav>li:nth-child(11)>a>span").addClass("sidebar-nav-sub-ico-rotate");
        $(".js-sidebar-nav>li:nth-child(11)>ul>li:nth-child(1)>a").addClass("active");
    </script>
    <!-- 内容区域 -->
    <div class="tpl-content-wrapper statement">
        <div class="row-content am-cf">
        <div class="row-content am-cf" style="min-width: 1000px;">

            <div class="row">
                <div class="am-u-sm-12 am-u-md-12 am-u-lg-12">
                    <div class="widget am-cf">
                        <div class="widget-head am-cf">
                            <div class="widget-title  am-cf">采购统计汇总</div>
                        </div>
                        <div class="widget-body  am-fr">
                            <div style="float: left;">
                                <div class="am-btn-toolbar">
                                    <div class="am-g">
                                        <div class="am-u-md-4 am-u-lg-4 am-form-group" style="width: 224px;">
                                            <button type="button" class="am-btn am-btn-default am-margin-right"
                                                    id="my-start">开始日期
                                            </button>
                                            <span id="my-startDate"></span>
                                        </div>
                                        <div class="am-u-md-4 am-u-lg-4 am-form-group"  style="width: 224px;">
                                            <button type="button" class="am-btn am-btn-default am-margin-right"
                                                    id="my-end">结束日期
                                            </button>
                                            <span id="my-endDate"></span>
                                        </div>
                                        <div class="am-u-md-4 am-u-lg-4 date-btn"  style="width: 224px;float: left;">
                                            <a href="javascript:;" onclick="getFiltersTime(30);">一个月</a>
                                            <a href="javascript:;" onclick="getFiltersTime(90);">一季度</a>
                                            <a href="javascript:;" onclick="getFiltersTime(365);">一年</a>
                                        </div>
                                    </div>
                                </div>
                            </div>
                            <div class="am-u-sm-12 am-u-md-2 am-u-lg-3" style="float: left;">

                                    <div class="am-form-group am-input-group am-input-group-sm tpl-form-border-form cl-p">

                                        <?php
                                        // 搜索栏显示的字的判断
                                        $type = isset($_GET['type']) ? $_GET['type'] : 'goods';
                                        switch ($type){
                                            case 'goods':
                                                $placeholder = '请输入商品名称';
                                                break;
                                            case 'gys':
                                                $placeholder = '请输入供应商名称';
                                                break;
                                            case 'order':
                                                $placeholder = '请输入进货单名称';
                                                break;
                                            case 'project':
                                                $placeholder = '请输入项目名称';
                                                break;
                                        }
                                        ?>
                                        <input type="text" class="am-form-field" name="search" id="searchValue" placeholder="<?php echo $placeholder ?>">
                                        	                                       
                                        <span class="am-input-group-btn">

                                            <a href="javascript:void(0)" id="search"
                                               class="am-btn  am-btn-default am-btn-success tpl-table-list-field am-icon-search">
                                                搜索
                                            </a>
                                        </span>
                                    </div>
                            </div>
                            
                            <div class="am-u-sm-12 am-form-group ">
                                <div class="am-btn-toolbar am-u-sm-12">
                                    <div class=" am-btn-group-xs">

                                        <a href="javascript:void(0);" onclick="goods()"
                                           class="am-btn   <?php if ($type == 'goods') {
                                               echo 'am-btn-primary';
                                           } else {
                                               echo 'am-btn-default';
                                           } ?> ">按商品</a>
                                        <a href="javascript:void(0);" onclick="gys()"
                                           class="am-btn  <?php if ($type == 'gys') {
                                               echo 'am-btn-primary ';
                                           } else {
                                               echo 'am-btn-default';
                                           } ?> ">按供应商</a>
                                        <a href="javascript:void(0);" onclick="order()"
                                           class="am-btn  <?php if ($type == 'order') {
                                               echo 'am-btn-primary ';
                                           } else {
                                               echo 'am-btn-default';
                                           } ?> ">按订单</a>
                                        <a href="javascript:void(0);" onclick="project()"
                                           class="am-btn  <?php if ($type == 'project') {
                                               echo 'am-btn-primary ';
                                           } else {
                                               echo 'am-btn-default';
                                           } ?> ">按项目</a>
                                    </div>
                                </div>
                            </div>
                            
                            <div class="am-u-sm-12 am-form-group ">
                                <div class="am-btn-toolbar am-u-sm-12">
                                    <div class=" am-btn-group-xs">
                                        <a href="javascript:void(0);" onclick="" class="am-btn am-btn-primary"><span
                                                    class="am-icon-download"></span> 导出</a>
                                    </div>
                                </div>
                            </div>
                        </div>
                        
                        <!--------------------- 列表开始 --------------------->
                        <div class="am-u-sm-12 am-u-md-12 am-u-lg-12 ul-table searchList">
                            <?php                            	
                                if (isset($list) && $list) {
                                // 商品
				                    echo '<ul>
			                                <li>商品编码</li>
			                                <li>商品名称</li>
			                                <li>商品规格</li>
			                                <li>商品来源</li>
			                                <li>所属供应商</li>
			                                <li>商品分类</li>
			                                <li>合计数量</li>
			                                <li>合计金额</li>
			                                <li>订单日期</li>
			                            </ul>';
										
                                } elseif(isset($gyslist) && $gyslist) {
                                	// 供应商
                                    echo '<table width="100%" class="am-table am-table-compact am-table-striped tpl-table-black " id="example-r">';
                                    echo '<thead><tr>
			                                <th>序号</th>
			                                <th>供应商编号</th>
			                                <th>供应商分类</th>
			                                <th>供应商名称</th>
			                                <th>商品数量</th>
			                                <th>采购金额</th>
			                                <th>地址</th>
			                                <th>联系人</th>
			                            </tr></thead>';
										
                                } elseif (isset($orderlist) && $orderlist) {
                                	// 订单
                                    echo '<table width="100%" class="am-table am-table-compact am-table-striped tpl-table-black " id="example-r">';
                                    echo '<thead><tr>
			                                <th>序号</th>
			                                <th>订单编号</th>
			                                <th>单据名称</th>
			                                <th>下单日期</th>
			                                <th>完成日期</th>
			                                <th>商品数量</th>
			                                <th>采购金额</th>
			                            </tr></thead>';
										
                                } elseif (isset($projectlist) && $projectlist) {
                                    echo '<table width="100%" class="am-table am-table-compact am-table-striped tpl-table-black " id="example-r">';
                                    echo '<thead><tr>
			                                <th>序号</th>
			                                <th>项目编号</th>
			                                <th>项目名称</th>
			                                <th>联系人</th>
			                                <th>商品数量</th>
			                                <th>采购金额</th>
			                                <th>项目日期</th>
			                              </tr></thead>';
                                }
                            ?>
                            
                            <?php                    
                            if (isset($list) && $list) {
                                // 2物料包、3书籍、4机器耗材、9打印机租赁、8供应商商品
                                foreach ($list as $v) {
                                    $dataId = $v['ckId'] ? $v['ckId'] : $v['id'];
                                    echo '<ul class="guige-ul">';

                                    if(substr($v['product_no'],0,3) == 'ist'){
                                    	echo '<li><a href="/admin/goods/editView?id='.$v['id'].'">' . $v['product_no'] . '</a></li>';
                                    }else{
                                        echo '<li>' . $v['product_no'] . '</li>';
                                    }

                                    	echo '
                                            <li>' . $v['name'] . '</li>
                                            <li class="guige"><i class="am-icon-caret-down" style="color: #0e90d2;"></i> 规格详情</li>
                                            <li>' . $v['source'] . '</li>
                                            <li>' . $v['supplier'] . '</li>
                                            <li>' . $v['one_category'] . '</li>
                                            <li>' . $v['quantity'] . '</li>
                                            <li>' . $v['priceAll'] . '</li>
                                            <li></li>
                                        <li class="guige-box"><ul>';
                                            foreach ($v['specification222'] as $v2){											
                                                echo	'<li date-id="' . $dataId . '">' . $v2['product_no'] . '</li>
                                                        <li>' . $v2['name'] . '</li>
                                                        <li>' . $v2['specification'] . '</li>
                                                        <li>' . $v['source'] . '</li>
                                                        <li>' . $v2['supplier'] . '</li>
                                                        <li>' . $v['one_category'] . '</li>
                                                        <li>' . $v2['quantity'] . '</li>
                                                        <li>' . $v2['priceAll'] . '</li>
                                                        <li>' . $v2['createTime'] . '</li>';

                                            }
                                            echo '</ul></li></ul>';
                                }
                            } elseif (isset($gyslist) && $gyslist) {
                            	echo '<tbody class="choose-box">';
                                foreach ($gyslist as $k2=>$v2) {
                                    echo '<tr>
                                    		<td>' . $v2['supplierId'] . '</td>
                                    		<td><a href="/admin/statement/orderSupplierDetail?supplierId='.$v2['supplierId'].'">' . $v2['code'] . '</a></td>
                                    		<td>' . $v2['type'] . '</td>
                                            <td>' . $k2 . '</td>
                                            <td>' . array_sum($v2['quantity']) . '</td>
                                            <td>' . number_format(array_sum($v2['priceAll']), 2) . '</td>
                                            <td>' . $v2['address'] . '</td>
                                            <td>' . $v2['linkMan'] . '</td>
                                          </tr>';
                                }
                                echo '</tbody></table>';
                            } elseif (isset($orderlist) && $orderlist) {
                                echo '<tbody class="choose-box">';
                                foreach ($orderlist as $v3) {
                                    $endTime = $v3['endTime'] ? date('Y-m-d',$v3['endTime']) : '该订单还未完成';
                                    echo '<tr>
                                    		<td>' . $v3['id'] . '</td>
                                    		<td><a href="/admin/procurement/purchaseEditView?id='.$v3['id'].'&status='.$v3['status'].'">' . $v3['purchaseCode'] . '</a></td>
                                    		<td>' .   $v3['name'] . '</td>
                                            <td>' . date('Y-m-d',$v3['createTime']) . '</td>
                                            <td>' . $endTime . '</td>
                                            <td>' . $v3['quantity'] . '</td>
                                            <td>' . number_format($v3['priceAll'], 2) . '</td>
                                          </tr>';
                                }
                                echo '</tbody></table>';
                            } elseif (isset($projectlist) && $projectlist) {
                                echo '<tbody class="choose-box">';

                                foreach ($projectlist as $k4=>$v4) {
                                    echo '<tr>
                                    		<td>' . $v4['projectId'] . '</td>
                                    		<td><a href="/admin/statement/orderProjectDetail?projectId='.$v4['projectId'].'">' . $v4['code'] . '</a></td>
                                    		<td>' .   $k4 . '</td>
                                            <td>' . $v4['linkMan'] . '</td>
                                            <td class="details-btn" data-am-modal="{target: \'#details\', closeViaDimmer: 0, width: 900, height: 500}">' . array_sum($v4['quantity']) . '</td>
                                            <td>' . number_format(array_sum($v4['priceAll']), 2) . '</td>
                                            <td>' . date('Y-m-d',$v4['createTime']) . '</td>
                                          </tr>';
                                }
                                echo '</tbody></table>';
                            }
                            ?>
                            
                            
                        </div>
                        <div class="am-u-lg-12">
                            <div class="am-u-sm-centered">
                                <ul class="am-pagination am-pagination-centered" id="paging">

                                </ul>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
<!-- 模态框 -->
<div class="am-modal am-modal-no-btn" tabindex="-1" id="details">
  <div class="am-modal-dialog">
    <div class="am-modal-hd">订单信息
      <a href="javascript: void(0)" class="am-close am-close-spin" data-am-modal-close>&times;</a>
    </div>
    <div class="am-modal-bd">
    	<table width="100%" class="am-table am-table-compact am-table-striped tpl-table-black " id="details-table">
            <thead>
	            <tr>
	                <th style="width: 120px">序号</th>
	                <th style="width: 120px">订单编号</th>
	                <th style="width: 120px">单据名称</th>
	                <th style="width: 120px">下单日期</th>
	                <th style="width: 100px">完成日期</th>
	                <th style="width: 100px">商品数量</th>
	                <th style="width: 90px">采购金额</th>
	            </tr>
            </thead>            
            <tbody>            	            	
            </tbody>
        </table>
    </div>
</div>
<script src="/assets/js/amazeui.min.js"></script>
<script src="/assets/js/amazeui.datatables.min.js"></script>
<script src="/assets/js/dataTables.responsive.min.js"></script>
<script src="/assets/js/app.js"></script>
<script src="/assets/js/page.js"></script>
<script>
    $(function () {

        //点击规格显示规格列表
        var unlock = false;
        $(document).on("click", ".guige", function () {
            if (unlock) {
                return false;
            }

            var guigeBox = $(this).siblings(".guige-box");
            var hasGuige = $(this).parent(".guige-ul").siblings(".guige-ul");
            var guigeLen = hasGuige.length;

            unlock = true;
            $(guigeBox).slideToggle(function () {
                unlock = false;
            });

            for (var i = 0; i < guigeLen; i++) {
                if (hasGuige.eq(i).children(".guige-box").css("display") != 'none') {
                    hasGuige.eq(i).children(".guige-box").slideToggle();
                }
            }

        });
    });
</script>

<script>
    function GetQueryString(name) {
        var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)");
        var r = window.location.search.substr(1).match(reg);
        if (r != null)return unescape(r[2]);
        return null;
    }
    function goods() {
        var search = GetQueryString('search');
        // $(".am-btn-primary").removeClass("am-btn-primary");
        // $(this).addClass("am-btn-primary");

        if (search == null) {
            window.location.href = '?page=1' + '&type=goods'
        } else {
            window.location.href = '?page=1' + '&search=' + search + '&type=goods'
        }
    }
    function gys() {
        var search = GetQueryString('search');
        if (search == null) {
            window.location.href = '?page=1' + '&type=gys'
        } else {
            window.location.href = '?page=1' + '&search=' + search + '&type=gys'

        }
    }
    function order() {
        var search = GetQueryString('search');
        if (search == null) {
            window.location.href = '?page=1' + '&type=order'
        } else {
            window.location.href = '?page=1' + '&search=' + search + '&type=order'

        }
    }
    function project() {
        var search = GetQueryString('search');
        if (search == null) {
            window.location.href = '?page=1' + '&type=project'
        } else {
            window.location.href = '?page=1' + '&search=' + search + '&type=project'

        }
    }



</script>

<script>

    //类型传参 type == 类型， search == 要搜索的
    $("#search").on("click",function () {
        var type = "<?php echo isset($_GET['type']) ? $_GET['type'] : 'goods' ?>";
        var search = $("#searchValue").val();
        var page = 1;
        var startTime = $("#my-startDate").text();
        var endTime = $("#my-endDate").text();
        chooseCheck(type,search,page,startTime,endTime);
    });


    //筛选日期
    var startDate = new Date(2014, 11, 20);
    var endDate = new Date(2100, 11, 25);
    var $alert = $('#data-alert');
    $('#my-start').datepicker().on('changeDate.datepicker.amui', function(event) {

        if (event.date.valueOf() > endDate.valueOf()) {
            $alert.find('p').text('开始日期应小于结束日期！').end().show();
            return false;

        } else {
            $alert.hide();
            startDate = new Date(event.date);
            $('#my-startDate').text($('#my-start').data('date'));
        }
        $(this).datepicker('close');

        startTime = $("#my-startDate").text();
        endTime = $("#my-endDate").text();
        search = $("#searchValue").val();
        page = 1;
        type = "<?php echo isset($_GET['type']) ? $_GET['type'] : 'goods' ?>";

        chooseCheck(type,search,page,startTime,endTime);

    });
    $('#my-end').datepicker().on('changeDate.datepicker.amui', function(event) {

        if (event.date.valueOf() < startDate.valueOf()) {
            $alert.find('p').text('结束日期应大于开始日期！').end().show();
            return false;
        } else {
            $alert.hide();
            endDate = new Date(event.date);
            $('#my-endDate').text($('#my-end').data('date'));
        }
        $(this).datepicker('close');

        startTime = $("#my-startDate").text();
        endTime = $("#my-endDate").text();
        search = $("#searchValue").val();
        page = 1;
        type = "<?php echo isset($_GET['type']) ? $_GET['type'] : 'goods' ?>";


        chooseCheck(type,search,page,startTime,endTime);

    });
    
    $(".details-btn").on("click",function () {
    	var projectId = $(this).parent().find("td:first-child").text();
    	projectId = projectId - 0;
		$.ajax({
    		type:"get",
    		url:"/api/statement/projectContent",
    		data: {
    			projectId: projectId
    		},
    		dateType : "json",
    		success: function (msg) {
    			var msg = $.parseJSON(msg);
    			var html = '';
    			var data = msg.goods;
    			for ( var i = 0; i < data.length; i ++ ) {
    				html += '<tr>';
	    			html += 	'<td>'+ data[i].dataId +'</td>';
	    			html += 	'<td>'+ data[i].product_no +'</td>';
	    			html += 	'<td>'+ data[i].name +'</td>';
	    			html += 	'<td>'+ changePhpTime(data[i].createTime) +'</td>';
	    			if (data[i].endTime) {
	    				html += 	'<td>'+ changePhpTime(data[i].endTime) +'</td>';
	    			} else {
	    				html += 	'<td></td>';
	    			}
	    			html += 	'<td>'+ data[i].quantity +'</td>';
	    			html += 	'<td>'+ data[i].priceAll +'</td>';
    				html += '</tr>';
    			}
    			$("#details-table").find("tbody").html(html);
    		},
    		error : function (data) {
                alert(XMLHttpRequest.status);
                alert(XMLHttpRequest.readyState);
                alert(textStatus);
            }
    	});
    });
    
    function changePhpTime (time) {
    	var y,m,d,date;
    	date = new Date(time*1000);
    	y = date.getFullYear() + '-';
    	m = (date.getMonth()+1 < 10 ? '0'+(date.getMonth()+1) : date.getMonth()+1) + '-';
    	d = date.getDate();
    	return y + m + d;
    }
    
    function getFiltersTime (a) {
   		var startY,startM,startD,endY,endM,endD,startTime,endTime;
		var endDate = new Date();
		startTime = endDate - 3600 * 1000 * 24 * a;
		startTime = new Date(startTime);
		startY = startTime.getFullYear();
		startM = (startTime.getMonth() + 1) < 10 ? '0' + (startTime.getMonth() + 1) : startTime.getMonth() + 1;
		startD = startTime.getDate() < 10 ? '0' + startTime.getDate() : startTime.getDate();
		startTime = startY + '-' + startM + '-' + startD;
		endY = endDate.getFullYear();
		endM = (endDate.getMonth() + 1) < 10 ? '0' + (endDate.getMonth() + 1) : endDate.getMonth() + 1;
		endD = endDate.getDate() < 10 ? '0' + endDate.getDate() : endDate.getDate();
		endTime = endY + '-' + endM + '-' + endD;
   		$("#my-startDate").text(startTime);
		$("#my-endDate").text(endTime);
    }

    function chooseCheck(type,search,page,startTime,endTime) {
        $.ajax({
            type: "GET",
            url : "/api/statement/orderSearch",
            data : {
                type : type,
                search : search,
                page: page,
                startTime:startTime,
                endTime: endTime
            },
            dateType : "json",
            beforeSend:function(){
                $(".my-dark").css("display","block");
            },
            success : function (msg) {
            	var msg = $.parseJSON(msg);
            	var data  = msg.goods;
            	console.log(msg);
                var type = GetQueryString('type');
                var searchList = '';
                if (msg.error) {
            		searchList = '<div style="text-align: center;">暂无数据</div>'
            	} else {
            		switch (type) 
					{
					case 'goods':
						searchList += '<ul>';
				        searchList +=   '<li>商品编码</li>';
				        searchList +=   '<li>商品名称</li>';
				        searchList +=   '<li>商品规格</li>';
				        searchList +=   '<li>商品来源</li>';
				        searchList +=   '<li>所属供应商</li>';
				        searchList +=   '<li>商品分类</li>';
				        searchList +=   '<li>合计数量</li>';
				        searchList +=   '<li>合计金额</li>';
				        searchList +=   '<li>订单日期</li>';
				        searchList += '</ul>';
				        for ( var i = 0; i < data.length; i++ ) {
				        	searchList += '<ul class="guige-ul">';
				        	searchList += '<li>'+ data[i].product_no + '</li>';
				        	searchList += '<li>'+ data[i].name +'</li>';
				        	searchList += '<li class="guige"><i class="am-icon-caret-down" style="color: #0e90d2;"></i> 规格详情</li>';
				        	searchList += '<li>'+ data[i].source +'</li>';
				        	searchList += '<li>'+ data[i].supplier +'</li>';
				        	searchList += '<li>'+ data[i].one_category +'</li>';
				        	searchList += '<li>'+ data[i].quantity +'</li>';
				        	searchList += '<li>'+ data[i].priceAll +'</li>';
				        	searchList += '<li></li>';
				        	searchList += '<li class="guige-box"><ul>';
				        	for ( var j = 0; j < data[i].specification222.length; j++ ) {
				        		searchList += '<li date-id="'+ data[i].specification222[j].dataId +'">'+ data[i].specification222[j].product_no +'</li>';
				        		searchList += '<li>'+ data[i].specification222[j].name +'</li>';
				        		searchList += '<li>'+ data[i].specification222[j].specification +'</li>';
				        		searchList += '<li>'+ data[i].specification222[j].source +'</li>';
				        		searchList += '<li>'+ data[i].specification222[j].supplier +'</li>';
				        		searchList += '<li>'+ data[i].specification222[j].one_category +'</li>';
				        		searchList += '<li>'+ data[i].specification222[j].quantity +'</li>';
				        		searchList += '<li>'+ data[i].specification222[j].priceAll +'</li>';
				        		searchList += '<li>'+ data[i].specification222[j].createTime +'</li>';
				        	}
				        	searchList += '</ul></li></ul>';
				        }
				        $(".searchList").html(searchList);
						break;
					case 'gys':
					
						searchList += '<table width="100%" class="am-table am-table-compact am-table-striped tpl-table-black " id="example-r">';
						searchList += '<thead>';
						searchList += 	'<tr>';
						searchList += 		'<th>序号</th>';
						searchList += 		'<th>供应商编号</th>';
						searchList += 		'<th>供应商分类</th>';
						searchList += 		'<th>供应商名称</th>';
						searchList += 		'<th>商品数量</th>';
						searchList += 		'<th>采购金额</th>';
						searchList += 		'<th>地址</th>';
						searchList += 		'<th>联系人</th>';
						searchList += 	'</tr>';
						searchList += '</thead>';
						searchList += '<tbody class="choose-box">';
						for ( var i in data ) {
							var quantity = null,priceAll = null;
							for (var j = 0; j < data[i].quantity.length; j++ ) {
								quantity += parseInt(data[i].quantity[j]);
							}
							for (var j = 0; j < data[i].priceAll.length; j++ ) {
								priceAll += parseFloat(data[i].priceAll[j]);
							}
							priceAll = priceAll.toFixed(2);
							searchList += '<tr>';
							searchList += '<td>' + data[i].supplierId + '</td>';
							searchList += '<td><a href="/admin/statement/orderSupplierDetail?supplierId=' + data[i].supplierId + '">' + data[i].code + '</a></td>';
							searchList += '<td>' + data[i].type + '</td>';
							searchList += '<td>' + i + '</td>';
							searchList += '<td>' + quantity + '</td>';
							searchList += '<td>' + priceAll + '</td>';
							searchList += '<td>' + data[i].address + '</td>';
							searchList += '<td>' + data[i].linkMan + '</td>';
							searchList += '<tr>';
						}
						searchList += '</tbody></table>';
						$(".searchList").html(searchList);
						break;
					case 'order':
				        searchList += '<table width="100%" class="am-table am-table-compact am-table-striped tpl-table-black " id="example-r">';
						searchList += '<thead>';
						searchList += 	'<tr>';
						searchList += 		'<th>序号</th>';
						searchList += 		'<th>订单编号</th>';
						searchList += 		'<th>单据名称</th>';
						searchList += 		'<th>下单日期</th>';
						searchList += 		'<th>完成日期</th>';
						searchList += 		'<th>商品数量</th>';
						searchList += 		'<th>采购金额</th>';
						searchList += 	'</tr>';
						searchList += '</thead>';
						searchList += '<tbody class="choose-box">';
						for ( var i = 0; i < data.length ;i++ ) {
							searchList += '<tr>';
							searchList += 	'<td>' + data[i].id + '</td>';
							searchList += 	'<td><a href="/admin/procurement/purchaseEditView?id=' + data[i].id + '&status=' + data[i].status + '">' + data[i].purchaseCode + '</a></td>';
							searchList += 	'<td>' + data[i].name + '</td>';
							searchList += 	'<td>' + data[i].createTime + '</td>';
							searchList += 	'<td>' + data[i].endTime + '</td>';
							searchList += 	'<td>' + data[i].quantity + '</td>';
							searchList += 	'<td>' + data[i].priceAll + '</td>';
							searchList += '<tr>';
						}
						searchList += '</tbody></table>';
						$(".searchList").html(searchList);
						break;
					case 'project':
			            searchList += '<table width="100%" class="am-table am-table-compact am-table-striped tpl-table-black " id="example-r">';
						searchList += '<thead>';
						searchList += 	'<tr>';
						searchList += 		'<th>序号</th>';
						searchList += 		'<th>项目编号</th>';
						searchList += 		'<th>项目名称</th>';
						searchList += 		'<th>联系人</th>';
						searchList += 		'<th>商品数量</th>';
						searchList += 		'<th>采购金额</th>';
						searchList += 		'<th>项目日期</th>';
						searchList += 	'</tr>';
						searchList += '</thead>';
						searchList += '<tbody class="choose-box">';
						for ( var i in data ) {
							var quantity = null,priceAll = null;
							for (var j = 0; j < data[i].quantity.length; j++ ) {
								quantity += parseInt(data[i].quantity[j]);
							}
							for (var j = 0; j < data[i].priceAll.length; j++ ) {
								priceAll += parseFloat(data[i].priceAll[j]);
							}
							priceAll = priceAll.toFixed(2);
							searchList += '<tr>';
							searchList += 	'<td>' + data[i].projectId + '</td>';
							searchList += 	'<td><a href="/admin/statement/orderProjectDetail?projectId=' + data[i].projectId + '">' + data[i].code + '</a></td>';
							searchList += 	'<td>' + i + '</td>';
							searchList += 	'<td>' + data[i].linkMan + '</td>';
							searchList += 	'<td>' + quantity + '</td>';
							searchList += 	'<td>' + priceAll + '</td>';
							searchList += 	'<td>' + data[i].createTime + '</td>';
							searchList += '<tr>';
						}
						break;
					}
            	}
				
				searchList += '</tbody></table>';
				$(".searchList").html(searchList);
				//分页
                //设置分页信息  
                var pageOptions = {  
                    AllowPaging: true,  
                    PageIndex: msg.currentPage,      //设置当前页码  
                    PageSize: msg.pageNum,       //设置分页大小  
                    RecordCount: msg.totalNum,  //设置数据总数  
                    // TotalPage: ,      //设置总页数
                    showPageCount: 4,
                    onPageClick: function(pageIndex) {  
                        chooseCheck(type,search,pageIndex,startTime,endTime);
                    }  
                }  
                //初始化分页栏  
                $('#paging').pageBar(pageOptions); 
            },
            complete:function(){
                $(".my-dark").css("display","none");
            },
            error : function (data) {
                alert(XMLHttpRequest.status);
                alert(XMLHttpRequest.readyState);
                alert(textStatus);
            }
       })
    }
</script>

<script>
      $(document).ready(function () {
          //设置分页信息
          var type = "<?php echo isset($_GET['type']) ? $_GET['type'] : 'goods' ?>";
          var pageOptions = {
              AllowPaging: true,
              PageIndex: <?php echo $_GET['page'] ?>,      //设置当前页码
              PageSize: <?php echo $pageNum; ?>,       //设置分页大小
              RecordCount: <?php echo $totalNum; ?>,  //设置数据总数
              // TotalPage: ,      //设置总页数
              showPageCount: 4,
              onPageClick: function (pageIndex) {
                  var page = parseInt(pageIndex);
                  window.location.href = "?page=" + page + "&type=" + type;
              }
          };
          //初始化分页栏
          $('#paging').pageBar(pageOptions);
      })
</script>
</body>

</html>